package se.webbzon.boltzmann.minigame.sandbox;

import java.util.ArrayList;
import java.util.Collection;

public abstract class DefaultSandBoxAnimation implements SandBoxAnimation {
	
	// A collection of all the animation listeners
	private final Collection<AnimationListener> listeners;

	/*============================================================
	Constructors
	============================================================*/
	
	public DefaultSandBoxAnimation() {
		listeners = new ArrayList<AnimationListener>();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Notifies to all the listeners that this sand box animation has completed. **/
	public void notifyComplete() {
		for (AnimationListener listener : listeners.toArray(new AnimationListener[0]))
			listener.onComplete(this);
	}

	@Override public boolean addListener(AnimationListener listener) {
		return listeners.add(listener);
	}

	@Override public boolean removeListener(AnimationListener listener) {
		return listeners.remove(listener);
	}
	
	/** Clears all listeners from this sand box animation. **/
	public void clearListeners() {
		listeners.clear();
	}

}
